package org.restoran.service.impl;

import java.io.Writer;
import java.util.Collection;

import org.restoran.model.Category;
import org.restoran.model.Order;
import org.restoran.repository.CategoryRepository;
import org.restoran.service.CategoryService;
import org.restoran.service.parser.Parser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Ievgen Pidvysotskyi
 */
@Repository
@Service("categoryService")
@Transactional (propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class CategoryServiceImpl implements CategoryService {

    private static Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);

    @Autowired
    public CategoryServiceImpl(Parser parser, CategoryRepository categoryRepository)
    {
        this.parser = parser;
        this.categoryRepository = categoryRepository;
    }

    private final Parser parser;
    private final CategoryRepository categoryRepository;

    @Override
    public Category findOne(Integer id) {
        return categoryRepository.findOne(id);
    }

    @Override
    public Iterable<Category> findAll() {
        return categoryRepository.findAll();
    }

    @Override
    public Category save(Category newEntity) {
        return categoryRepository.save(newEntity);
    }

    @Override
    public void delete(Category deleted) {
        categoryRepository.delete(deleted);

    }

    @Override
    public void delete(Integer deletedId) {
        categoryRepository.delete(deletedId);
    }


    @Override
    public String parseToJson(Category entity) {
        return parser.toJson(entity);
    }

    @Override
    public void parseToJson(Writer writer, Category entity) {
        parser.toJson(writer, entity);
    }

    @Override
    public String parseToJson(Collection<Category> objects) {
        return parser.toJson(objects);
    }

    @Override
    public void parseToJson(Writer writer, Collection<Category> args) {
        parser.toJson(writer, args);
    }

    @Override
    public Category parseFromJson(String json, Class<Category> type) {
        return parser.fromJson(json, type);
    }
}